/*
 * spi.c
 *
 * Created: 08.02.2013 12:36:33
 *  Author: saenko
 */ 
#include <stdio.h>
#include <avr/io.h>

#include "definitions.h"

void spi_init_master(void)
{
	sbi(DDRB,3); //mosi
	cbi(DDRB,4); //miso
	sbi(DDRB,5); //sck
	
	sbi(PORTC,0);
	sbi(DDRC,0); //sc
	
	
	
	SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
	
}

unsigned char spi_write_byte(unsigned char data)
{
	/* Start transmission */
	SPDR = data;
	/* Wait for transmission complete */
	while(!(SPSR & (1<<SPIF)));
	
	return SPDR;
}
